//
//  ShareManager.m
//  FbeeAPP
//
//  Created by dev-m on 2018/3/23.
//  Copyright © 2018年 mohao. All rights reserved.
//

#import "ShareManager.h"
#import "WXApi.h"

@implementation ShareManager

+(instancetype)sharedManager
{
    static dispatch_once_t queue;
    static ShareManager * manager = nil;
    
    dispatch_once(&queue, ^{
        manager = [[ShareManager alloc]init];
    });
    
    return manager;
}


-(void)shareImg:(UIImage *)img type:(ShareType)type
{
    //朋友圈
    if (type == WxMomentsShare) {
        WXMediaMessage *message =[WXMediaMessage message];
        
        //创建分享内容对象
        WXImageObject *imgObj = [WXImageObject object];
        imgObj.imageData =UIImageJPEGRepresentation(img, 0.5);
        message.mediaObject = imgObj;
        
        //创建发送对象实例
        SendMessageToWXReq *sendReq = [[SendMessageToWXReq alloc] init];
        sendReq.bText = NO;//不使用文本信息
        sendReq.scene = WXSceneTimeline;//0 = 好友列表 1 = 朋友圈 2 = 收藏
        sendReq.message = message;
        
        
        
        //发送分享信息
        [WXApi sendReq:sendReq];
    }
    
    //微信好友
    if (type == WxShare) {
        //创建发送对象实例
        SendMessageToWXReq *sendReq = [[SendMessageToWXReq alloc] init];
        sendReq.bText = NO;//不使用文本信息
        sendReq.scene = WXSceneSession;//0 = 好友列表 1 = 朋友圈 2 = 收藏
        
        //创建分享内容对象
        WXMediaMessage *urlMessage = [WXMediaMessage message];
        
        //创建多媒体对象
        WXImageObject *imageObject = [WXImageObject object];
        imageObject.imageData =UIImageJPEGRepresentation(img, 0.5);
        //完成发送对象实例
        urlMessage.mediaObject = imageObject;
        sendReq.message = urlMessage;
        
        //发送分享信息
        [WXApi sendReq:sendReq];
    }
}

@end
